//
//  CTCommentView.m
//  ConstellationTalk_0.1
//
//  Created by riley on 15/6/1.
//  Copyright (c) 2015年 riley chu. All rights reserved.
//

#import "CTCommentView.h"
#import "CTHeader.h"
#import "CTCommentCell.h"
#import "CTAppLanguage.h"
#import "CTDebugManager.h"
#import "UIViewAdditions.h"
#import "CTDiscoveryItems.h"
#import "CTRequestUtil.h"
#import "CTDeviceFunction.h"
#import "CTUser.h"
#import "CTUserItem.h"
#import "CTTextManager.h"
#import "CTLogicItems.h"
#import "RefreshControl.h"
#import "CTLogin.h"
#import "CTTopicView.h"
#import "CTTextManager.h"
#import "CTFile.h"
#import "CTDeviceFunction.h"

@interface CTCommentView()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,CommentFavourHeadBtnDelegate,RefreshControlDelegate,CTTopicViewDelegate,CTCommentCellDelegate>
{
    UITableView     *commentTableView;
    UIView          *topView;
    UIView          *bottomView;
    UILabel         *commentTextBox;
    UITextView      *commentTextView;
    UIButton        *commentSendBtn;
    CGRect          bottomViewRect;
    BOOL            isKeyBoardShow;
    float           bottomView_y;
    
    UITapGestureRecognizer *tapGesture;
    
    
    //headerView
    UIView          *backGroundView;
    UIButton        *headerImageView;
    UIImageView     *sexImageView;
    UILabel         *nameLabel;
    UILabel         *attentionLabel;
    UIButton        *attentionBtn;
    UIImageView     *sqcImageView;
    UILabel         *sqcLabel;
    CTTopicView     *topicView;
    UILabel         *timeLabel;
    UIImageView     *picImageView;
    UIButton        *favourBtn;
    UILabel         *favourLabel;
    UILabel         *favCountLabel;
    UIView          *favHeadView;
    CTFollowList    *commentItem;
    CTListDetailUser*listDetaiItme;
    NSMutableArray  *favArray;
    BOOL            favBool;
    BOOL            attentionBtnBool;
    int             favNumber;
    UIButton        *shareBtn;
    UIButton        *moreBtn;
    UIImageView     *favImageView;
    
    NSArray * commentArray;
    RefreshControl  *refreshControl;
    UILabel *backGroundBottomLine;
}

@end

@implementation CTCommentView

@synthesize delegate;

- (void)dealloc
{
    [backGroundBottomLine removeFromSuperview];
    backGroundBottomLine = nil;
    delegate = nil;
    favArray = nil;
    commentItem = nil;
    [shareBtn removeFromSuperview];
    shareBtn = nil;
    [favImageView removeFromSuperview];
    favImageView = nil;
    [moreBtn removeFromSuperview];
    moreBtn = nil;
    [commentSendBtn removeFromSuperview];
    commentSendBtn = nil;
    [topicView removeFromSuperview];
    topicView = nil;
    [commentTableView removeFromSuperview];
    commentTableView = nil;
    [topView removeFromSuperview];
    topView = nil;
    [bottomView removeFromSuperview];
    bottomView = nil;
    [commentTextBox removeFromSuperview];
    commentTextBox = nil;
    [commentTextView removeFromSuperview];
    commentTextView = nil;
    //headerView
    [backGroundView removeFromSuperview];
    backGroundView = nil;
    [headerImageView removeFromSuperview];
    headerImageView = nil;
    [sexImageView removeFromSuperview];
    sexImageView = nil;
    [nameLabel removeFromSuperview];
    nameLabel = nil;
    [attentionLabel removeFromSuperview];
    attentionLabel = nil;
    [attentionBtn removeFromSuperview];
    attentionBtn = nil;
    [sqcImageView removeFromSuperview];
    sqcImageView = nil;
    [sqcLabel removeFromSuperview];
    sqcLabel = nil;
    [timeLabel removeFromSuperview];
    timeLabel = nil;
    [picImageView removeFromSuperview];
    picImageView = nil;
    [favourBtn removeFromSuperview];
    favourBtn = nil;
    [favourLabel removeFromSuperview];
    favourLabel = nil;
    [favCountLabel removeFromSuperview];
    favCountLabel = nil;
    [favHeadView removeFromSuperview];
    favHeadView = nil;
    
    commentArray = nil;
    
    DeviceTypeAdaptation adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (adaptation != iPhone4_4s) {
        refreshControl = nil;
    }
    
    [tapGesture removeTarget:self action:@selector(tapGestureAction:)];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
    
    [CTDebugManager showErrorLogInfo:@"dealloc : CTCommentView Is Removed!!!!"];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT);
        isKeyBoardShow = NO;
        [self createHeaderView];

        [self createTopTitlView];
        [self createCommentListTableView];
        [self createBottomView];
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
    }
    return self;
}
- (void)createTopTitlView
{
    topView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 64)];
    topView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [self addSubview:topView];
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, CT_HEADER_SCREEN_WIDTH, 44)];
    titleLabel.text = [CTAppLanguage localizedStringForKey:@"commentView_topTitle" withValue:nil withTable:@"Language"];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = CT_HEADER_GREEN_COLOR;
    titleLabel.font = [UIFont fontWithName:nil size:19];
    [topView addSubview:titleLabel];
    
    UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
    backButton.frame = CGRectMake(0, 20, 44, 44);
    [backButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:CT_HEADER_BACK_IMAGE_CLICK] forState:UIControlStateHighlighted];
    [topView addSubview:backButton];
    
    
    UILabel * topBottomLine = [[UILabel alloc]initWithFrame:CGRectMake(0, topView.height-0.5, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [topView addSubview:topBottomLine];
//    //增加监听，当键盘出现或改变时收出消息
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillShow:)
//                                                 name:UIKeyboardWillShowNotification
//                                               object:nil];
//    
//    //增加监听，当键退出时收出消息
//    [[NSNotificationCenter defaultCenter] addObserver:self
//                                             selector:@selector(keyboardWillHide:)
//                                                 name:UIKeyboardWillHideNotification
//                                               object:nil];
    
}
- (void)createHeaderView
{
    backGroundView  = [[UIView alloc]init];
    backGroundView.userInteractionEnabled = YES;
    backGroundView.backgroundColor = CT_HEADER_WHITE_COLOR;
    tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction:)];
    [backGroundView addGestureRecognizer:tapGesture];
    //头像
    headerImageView = [UIButton buttonWithType:UIButtonTypeCustom];
    headerImageView.frame = CGRectMake(10, 25, 45, 45);
    [headerImageView setBackgroundImage:[UIImage imageNamed:@"head"] forState:UIControlStateNormal];
    [headerImageView addTarget:self action:@selector(headImageBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    headerImageView.adjustsImageWhenHighlighted = NO;
    headerImageView.layer.masksToBounds = YES;
    headerImageView.layer.cornerRadius  = 22.5;
    [backGroundView addSubview:headerImageView];
    //性别
    sexImageView = [[UIImageView alloc]initWithFrame:CGRectMake(40,headerImageView.origin.y+30, 15, 15)];
    sexImageView.image = [UIImage imageNamed:@"xingbie_female"];//男 male
    [backGroundView addSubview:sexImageView];
    //名字
    nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(headerImageView.right+10, 30, CT_HEADER_SCREEN_WIDTH-65-70, 18)];
    nameLabel.font =[UIFont systemFontOfSize:18.0f];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.textColor = CT_HEADER_BLACK_COLOR;
    //    nameLabel.backgroundColor = [UIColor redColor];
    [backGroundView addSubview:nameLabel];
    //关注按钮
    attentionLabel = [[UILabel alloc]initWithFrame:CGRectMake(CT_HEADER_SCREEN_WIDTH-60, 30, 50, 23)];
    attentionLabel.font = [UIFont systemFontOfSize:13.0];
    attentionLabel.textAlignment = NSTextAlignmentCenter;
    attentionLabel.textColor = CT_HEADER_GREEN_COLOR;
    [backGroundView addSubview:attentionLabel];
    attentionLabel.hidden = YES;
    attentionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    attentionBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-60, 30, 50, 23);
    [attentionBtn addTarget:self action:@selector(attentionBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [backGroundView addSubview:attentionBtn];
    attentionBtn.hidden = YES;
    
    //认证画师
    sqcImageView = [[UIImageView alloc]initWithFrame:CGRectMake(headerImageView.right+10, nameLabel.bottom+5, 13, 13)];
    sqcImageView.image = [UIImage imageNamed:@"vip"];
    [backGroundView addSubview:sqcImageView];
    
    //认证画师Label
    sqcLabel = [[UILabel alloc]initWithFrame:CGRectMake(sqcImageView.right+5, nameLabel.bottom+8, CT_HEADER_SCREEN_WIDTH-65-70-30, 10)];
    sqcLabel.font =[UIFont systemFontOfSize:10.0f];
    sqcLabel.textAlignment = NSTextAlignmentLeft;
    sqcLabel.text = [CTAppLanguage localizedStringForKey:@"userView_label_vipLabel" withValue:nil withTable:@"Language"];
    sqcLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    //    sqcLabel.backgroundColor = [UIColor redColor];
    [backGroundView addSubview:sqcLabel];
    
    
    //时间
    timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 35, CT_HEADER_SCREEN_WIDTH-20, 12)];
    timeLabel.font =[UIFont systemFontOfSize:12.0f];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.textColor = [UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
    timeLabel.backgroundColor = [UIColor clearColor];
    timeLabel.text = @"1分钟前";
    timeLabel.hidden = YES;
    [backGroundView addSubview:timeLabel];
    //大图
    picImageView = [[UIImageView alloc]init];
    picImageView.frame = CGRectMake(0, headerImageView.bottom+13, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_WIDTH);
    picImageView.userInteractionEnabled = YES;
    picImageView.backgroundColor = [UIColor clearColor];
    picImageView.image = [UIImage imageNamed:@"faxianguanzhu"];
    [backGroundView addSubview:picImageView];
    UITapGestureRecognizer *picTapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(picImageBtnAction:)];
    [picImageView addGestureRecognizer:picTapGesture];
    
    //描述
//    describeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, picImageView.bottom+7.5, CT_HEADER_SCREEN_WIDTH-20, 40)];
//    describeLabel.font = [UIFont systemFontOfSize:15.0f];
//    describeLabel.backgroundColor = [UIColor clearColor];
//    describeLabel.textColor =[UIColor colorWithRed:164/255.0 green:164/255.0 blue:164/255.0 alpha:1.0];
//    describeLabel.textAlignment = NSTextAlignmentLeft;
//    describeLabel.numberOfLines = 2;
//    describeLabel.lineBreakMode = NSLineBreakByCharWrapping;
//    [backGroundView addSubview:describeLabel];
    topicView  = [[CTTopicView alloc]initWithFrame:CGRectMake(10, picImageView.bottom+15, CT_HEADER_SCREEN_WIDTH, 10)];
    topicView.delegate = self;
    [backGroundView addSubview:topicView];
    
    //点赞
    favourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [favourBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_dianzan"] forState:UIControlStateNormal];
    [favourBtn addTarget:self action:@selector(favourBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [backGroundView addSubview:favourBtn];
    favourLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 35, 24)];
    favourLabel.font =[UIFont systemFontOfSize:13.0f];
    favourLabel.textAlignment = NSTextAlignmentLeft;
    favourLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_favourLabel_title" withValue:nil withTable:@"Language"];
    favourLabel.textColor = CT_HEADER_BLACK_COLOR;
    [favourBtn addSubview:favourLabel];
    

    
    //分享
    shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_zhuanfa"] forState:UIControlStateNormal];
    [shareBtn addTarget:self action:@selector(shareBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [backGroundView addSubview:shareBtn];
    UILabel * shareLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 0, 35, 24)];
    shareLabel.font =[UIFont systemFontOfSize:13.0f];
    shareLabel.textAlignment = NSTextAlignmentLeft;
    shareLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_shareLabel_title" withValue:nil withTable:@"Language"];
    shareLabel.textColor = CT_HEADER_BLACK_COLOR;
    shareLabel.backgroundColor = [UIColor clearColor];
    [shareBtn addSubview:shareLabel];
    
    moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreBtn setBackgroundImage:[UIImage imageNamed:@"follow_more"] forState:UIControlStateNormal];
    [moreBtn addTarget:self action:@selector(moreBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [backGroundView addSubview:moreBtn];
    
//    favImageView = [[UIImageView alloc]init];
//    favImageView.image = [UIImage imageNamed:@"renshu_dianzanrenshu"];
//    [backGroundView addSubview:favImageView];
    
//    favCountLabel = [[UILabel alloc]init];
//    favCountLabel.font =[UIFont systemFontOfSize:15.0f];
//    favCountLabel.textAlignment = NSTextAlignmentLeft;
//    favCountLabel.text = @"999W";
//    //    commentLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_commentLabel_title" withValue:nil withTable:@"Language"];
//    favCountLabel.textColor = CT_HEADER_BLACK_COLOR;
//    //    favCountLabel.backgroundColor = [UIColor redColor];
//    [backGroundView addSubview:favCountLabel];
    backGroundBottomLine = [[UILabel alloc]init];
    [backGroundView addSubview:backGroundBottomLine];
    
    favHeadView = [[UIView alloc]init];
    [backGroundView addSubview:favHeadView];

}

- (void)createCommentListTableView
{
    commentTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, CT_HEADER_SCREEN_WIDTH, CT_HEADER_SCREEN_HEIGHT-64-50) style:UITableViewStylePlain];
    commentTableView.delegate = self;
    commentTableView.dataSource = self;
//    commentTableView.showsVerticalScrollIndicator = NO;
//    commentTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//    commentTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    commentTableView.backgroundColor = CT_HEADER_WHITE_COLOR;
    [commentTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [self addSubview:commentTableView];
    
    
    /*
     *** refresh control
     */
    DeviceTypeAdaptation adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (adaptation != iPhone4_4s) {
        refreshControl = [[RefreshControl alloc] initWithScrollView:commentTableView delegate:self];
        refreshControl.topEnabled = YES;
        refreshControl.bottomEnabled = NO;
        refreshControl.enableInsetBottom = 60;

    }
   
    
}
- (void)createBottomView
{
    bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-50, CT_HEADER_SCREEN_WIDTH, 50)];
    bottomView.backgroundColor = CT_HEADER_WHITE_COLOR;
    bottomViewRect = bottomView.frame;
    [self addSubview:bottomView];
    
    UILabel *topLineLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, 0.5)];
    topLineLabel.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
    [bottomView addSubview:topLineLabel];
    
    commentTextBox = [[UILabel alloc]initWithFrame:CGRectMake(42.5, 7.5, CT_HEADER_SCREEN_WIDTH-83-42.5, 35)];
    commentTextBox.backgroundColor = CT_HEADER_WHITE_COLOR;
    commentTextBox.layer.cornerRadius   = 4.0f;
    commentTextBox.layer.masksToBounds  = YES;
    CALayer *btnlayer = [commentTextBox layer];
        btnlayer.borderColor = [CT_HEADER_DEEPLINE_COLOR CGColor];
        btnlayer.borderWidth = 0.5f;
    [bottomView addSubview:commentTextBox];
    
    commentTextView = [[UITextView alloc]initWithFrame:CGRectMake(commentTextBox.origin.x+10, commentTextBox.origin.y, commentTextBox.width-20, 35)];
    commentTextView.font = [UIFont systemFontOfSize:15.0f];
    commentTextView.textColor = [UIColor colorWithRed:201/255.0 green:201/255.0 blue:197/255.0 alpha:1.0];
    commentTextView.delegate = self;
    commentTextView.backgroundColor = [UIColor clearColor];
    commentTextView.textAlignment = NSTextAlignmentLeft;
    commentTextView.text = [CTAppLanguage localizedStringForKey:@"commentView_addComment_title" withValue:nil withTable:@"Language"];
    [bottomView addSubview:commentTextView];
    
    commentSendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    commentSendBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-15-53, bottomView.height-10-30, 53, 30);
    [commentSendBtn setBackgroundImage:[UIImage imageNamed:@"send"] forState:UIControlStateNormal];
    [commentSendBtn addTarget:self action:@selector(commentSendBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [commentSendBtn setTitle:[CTAppLanguage localizedStringForKey:@"commentView_sender_title" withValue:nil withTable:@"Language"] forState:UIControlStateNormal];
    [commentSendBtn setTitleColor:CT_HEADER_WHITE_COLOR forState:UIControlStateNormal];
    [bottomView addSubview:commentSendBtn];
    
}
//收回键盘
- (void)tapGestureAction:(UITapGestureRecognizer *) sender
{
//    bottomView.frame = CGRectMake(bottomView.origin.x, bottomView.origin.y, bottomView.width, bottomView.height);
//    commentTextBox.frame = CGRectMake(commentTextBox.origin.x, commentTextBox.origin.y, commentTextBox.width, commentTextBox.height);
//    commentTextView.frame = CGRectMake(commentTextView.origin.x, commentTextView.origin.y, commentTextView.width, commentTextView.height);
//    if (isKeyBoardShow == NO)
//    {
//        isKeyBoardShow = YES;
//    }
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    
}
//发送按钮
- (void)commentSendBtnAction:(UIButton *) sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];
   
    if ([self.delegate respondsToSelector:@selector(commentViewSendBtnAction:withText:)])
    {
        if([commentTextView.text isEqualToString:@"添加评论"])
        {
            [self.delegate commentViewSendBtnAction:self withText:nil];

        }
        else
        {
            [self.delegate commentViewSendBtnAction:self withText:commentTextView.text];
        }
    }
     commentTextView.text = @"添加评论";
}
//返回按钮
- (void)backButtonAction:(UIButton *) sender
{
    if ([self.delegate respondsToSelector:@selector(commentViewBackBtnAction:)])
    {
        [self.delegate commentViewBackBtnAction:self];
    }
}
//#pragma CTCommentCell Delegate
//-(void)clickHeadBtnAction:(CTCommentCell *)cell withItem:(CTCommentListItems *)item
//{
//    if ([self.delegate respondsToSelector:@selector(commentViewHitHeadBtnAction:withItem:)])
//    {
//        [self.delegate commentViewHitHeadBtnAction:self withItem:item];
//    }
//}

#pragma mark TextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    CTTextManager  *textManager =  [CTTextManager shareInstance];
    if ([textManager isFoundString:textView.text withStr:@"添加评论"] == YES)
    {
        textView.text = nil;
    }
}
- (void)textViewDidChange:(UITextView *)textView
{
//    float conthtSizeHeight = textView.contentSize.height;
//    bottomView.frame = CGRectMake(0, bottomView_y-conthtSizeHeight+30, CT_HEADER_SCREEN_WIDTH, conthtSizeHeight+30);
//    commentTextView.frame = CGRectMake(commentTextView.origin.x, commentTextView.origin.y, commentTextView.width, textView.contentSize.height);
//    commentTextBox.frame = CGRectMake(commentTextBox.origin.x, commentTextBox.origin.y, CT_HEADER_SCREEN_WIDTH-83-42.5, textView.contentSize.height);
    
   
    
    
    }
- (void)textViewDidEndEditing:(UITextView *)textView
{
//     bottomViewRect = bottomView.frame;
//    isKeyBoardShow = YES;
    CTTextManager  *textManager =  [CTTextManager shareInstance];
    if ([textManager isBlankString:textView.text] == YES)
    {
        textView.text = @"添加评论";
    }
//    bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, CT_HEADER_SCREEN_HEIGHT-50, CT_HEADER_SCREEN_WIDTH, 50)];
//    bottomViewRect = bottomView.frame;
//    commentTextBox = [[UILabel alloc]initWithFrame:CGRectMake(42.5, 7.5, CT_HEADER_SCREEN_WIDTH-83-42.5, 35)];
//    commentTextView = [[UITextView alloc]initWithFrame:CGRectMake(commentTextBox.origin.x+10, commentTextBox.origin.y, commentTextBox.width-20, 35)];
}

#pragma mark-UITableViewDataSource


//分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return commentArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    CTCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell.delegate = self;
        cell = [[CTCommentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    CTCommentListItems * commentListItem = [commentArray objectAtIndex:indexPath.row];
    cell.commentListItem = commentListItem;
    cell.commentStr = commentListItem.commentItem.text;
    cell.imgUrl = commentListItem.commentItem.user.profile_image_url_thumb;
    cell.nameStr = commentListItem.commentItem.user.name;
    cell.timeStr = commentListItem.commentItem.update_time;
    commentTableView.rowHeight = [self LabelHeightfontSize:15.0f withText:commentListItem.commentItem.text]+65;
    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    CTCommentListItems * commentListItem = [commentArray objectAtIndex:indexPath.row];
    
    if ([self.delegate respondsToSelector:@selector(commentViewDeleteCommentAction:withItem:withCommentUser:)]) {
        [self.delegate commentViewDeleteCommentAction:self withItem:commentItem withCommentUser:commentListItem];
    }
}

//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//    if (commentArray.count > 0) {
//        CTCommentListItems * commentListItem = [commentArray objectAtIndex:indexPath.row];
//        
//        BOOL isCanEdite;
//        if ([CTLogin isUserLoginState] == YES) {
//            
//            CTUserItem * userItem = [CTUser userInfo];
//            if ([commentItem.user.uid isEqualToString:userItem.uid]) {
//                isCanEdite = YES;
//            }else{
//                
//                if ([commentListItem.commentItem.user.uid isEqualToString:userItem.uid]) {
//                    isCanEdite = YES;
//                }else{
//                    isCanEdite = NO;
//                }
//            }
//            
//        }else{
//            isCanEdite = NO;
//        }
//        
//        return isCanEdite;
//    }
//    
//    return NO;
//}

- (float)LabelHeightfontSize:(float)fontSize withText:(NSString *)commentStr
{
    CGSize  titleSize = [commentStr sizeWithFont:[UIFont systemFontOfSize:fontSize]
                               constrainedToSize:CGSizeMake(CT_HEADER_SCREEN_WIDTH-58-40, 2000)
                                   lineBreakMode:NSLineBreakByCharWrapping];

    return titleSize.height;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];
    CTCommentListItems * commentListItem = [commentArray objectAtIndex:indexPath.row];
    if ([self.delegate respondsToSelector:@selector(commentViewHitHeadBtnAction:withItem:)])
    {
        [self.delegate commentViewHitHeadBtnAction:self withItem:commentListItem];
    }
}


#pragma mark - notification handler

- (void)keyboardWillChangeFrame:(NSNotification *)notification
{
    NSDictionary *info = [notification userInfo];
    CGFloat duration = [[info objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
    NSValue *aValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    float height = keyboardRect.size.height;
    CGRect inputFieldRect = bottomViewRect;
    inputFieldRect.origin.y -= height;
    if (isKeyBoardShow == NO)
    {
        
        NSLog(@"NO =====%f",bottomView_y);
        [UIView animateWithDuration:duration animations:^{
            bottomView.frame= inputFieldRect;
        }];
//        isKeyBoardShow = YES;
        bottomView_y = bottomView.origin.y;
    }
    else
    {
        
        
//        if (bottomView_y<= CT_HEADER_SCREEN_HEIGHT-bottomView.height)
//        {
//        }
        NSLog(@"YES =====%f",bottomView_y);
        [UIView animateWithDuration:duration animations:^{
            bottomView.frame= bottomViewRect;
        }];
        bottomView_y = bottomView.origin.y;
        isKeyBoardShow = NO;
    }
    NSLog(@"isNOORYES = %d",isKeyBoardShow);

}



#pragma mark - action & delegate -
-(void)refresh
{
    
    
    DeviceTypeAdaptation adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (adaptation != iPhone4_4s) {
        [refreshControl startRefreshingDirection:RefreshDirectionTop];
    }
}

-(void)refreshPullDownEnd
{
    DeviceTypeAdaptation adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (adaptation != iPhone4_4s) {
        [refreshControl finishRefreshingDirection:RefreshDirectionTop];

    }
}

-(void)refreshPullUpEnd
{
    DeviceTypeAdaptation adaptation = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (adaptation != iPhone4_4s) {
       [refreshControl finishRefreshingDirection:RefreshDirectionBottom];
    }
  
}

-(void)reloadData
{
    [commentTableView reloadData];
}

#pragma mark - refresh control delegate -

- (void)refreshControl:(RefreshControl *)refreshControl didEngageRefreshDirection:(RefreshDirection) direction
{
    if (direction == RefreshDirectionTop) {
        if ([self.delegate respondsToSelector:@selector(refreshControlPullDown:)]) {
            [self.delegate refreshControlPullDown:self];
        }
        
    }else{
        if ([self.delegate respondsToSelector:@selector(refreshControlPullUp:)]) {
            [self.delegate refreshControlPullUp:self];
        }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (scrollView.contentOffset.y >= 0.0 && scrollView.contentOffset.y < 80) {
        [refreshControl finishRefreshingDirection:RefreshDirectionTop];
    }
    if (scrollView.contentOffset.y + scrollView.frame.size.height<= scrollView.contentSize.height && scrollView.contentOffset.y + scrollView.frame.size.height >= scrollView.contentSize.height - 80) {
        [refreshControl finishRefreshingDirection:RefreshDirectionBottom];
    }
    
    if (scrollView.contentOffset.y + scrollView.frame.size.height <= scrollView.contentSize.height+50) {
        refreshControl.isPullDown = YES;
    }else{
        refreshControl.isPullDown = NO;
    }
    
}






#pragma  mark - setter -

-(void)setCommentListItems:(NSArray *)commentListArray
{
    
    @try {
        NSMutableDictionary * infoMutableDic = [CTFile getDicFile:@"commentList.plist" fromDoc:CTFileDocLibrary fromPath:@"cacheData/other"];
        
        if ([[NSString stringWithFormat:@"%@",[infoMutableDic objectForKey:@"next_page"]] isEqualToString:@"1"])refreshControl.bottomEnabled = YES;
        else refreshControl.bottomEnabled = NO;
    }
    @catch (NSException *exception) {
        refreshControl.bottomEnabled = NO;
    }
    
    commentArray = commentListArray;
    [commentTableView reloadData];
}

- (void)setFollowListItem:(CTFollowList *)followListItem
{
    
    commentItem = followListItem;
   
    [CTRequestUtil requestImgWithUrl:commentItem.user.profile_image_url_thumb withCompletionSuccessHandler:^(UIImage *img) {
        [headerImageView setBackgroundImage:img forState:UIControlStateNormal];
    } withFailedHandler:^(NSError *error) {
        
    }];
    
    if ([commentItem.user.gender isEqualToString:@"1"])
    {
        sexImageView.image = [UIImage imageNamed:@"xingbie_male"];
    }
    else
    {
        sexImageView.image = [UIImage imageNamed:@"xingbie_female"];
    }
    nameLabel.text = commentItem.user.name;
    if ([commentItem.user.following isEqualToString:@"1"])
    {
        attentionBtnBool = YES;
        attentionLabel.hidden = NO;
        attentionBtn.hidden  = NO;
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_ok_bg"] forState:UIControlStateNormal];
        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attentioned_title" withValue:nil withTable:@"Language"];
        attentionLabel.textColor = timeLabel.textColor;
        if ([commentItem.user.uid isEqualToString:[CTUser userInfo].uid])
        {
            attentionBtn.hidden = YES;
            attentionLabel.hidden = YES;
            timeLabel.hidden = NO;
        }

    }
    else
    {
        attentionBtnBool = NO;
        attentionBtn.hidden = NO;
        attentionLabel.hidden = NO;
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_bg"] forState:UIControlStateNormal];
        attentionLabel.text =[CTAppLanguage localizedStringForKey:@"fllow_attention_title" withValue:nil withTable:@"Language"];
        attentionLabel.textColor = CT_HEADER_GREEN_COLOR;
        if ([commentItem.user.uid isEqualToString:[CTUser userInfo].uid])
        {
            attentionBtn.hidden = YES;
            attentionLabel.hidden = YES;
            timeLabel.hidden = NO;
        }
        
    }
    if([commentItem.user.verified isEqualToString:@"1"])
    {
        sqcImageView.hidden = NO;
        sqcLabel.hidden = NO;
    }
    else
    {
        sqcImageView.hidden = YES;
        sqcLabel.hidden = YES;
    }
    
//    timeLabel.text = commentItem.update_time;
    CTTextManager *textManager = [CTTextManager shareInstance];
    timeLabel.text = [textManager timestampToTime:commentItem.update_time];
    
    [CTRequestUtil requestImgWithUrl:commentItem.pic_url withCompletionSuccessHandler:^(UIImage *img) {
        picImageView.image = img;
    } withFailedHandler:^(NSError *error) {
        
    }];
    
    topicView.item = followListItem;
    if (commentItem.topic_list.count < 1 && commentItem.text.length < 1)
    {
        favourBtn.frame = CGRectMake(10, picImageView.bottom+15, 65, 24);
        shareBtn.frame = CGRectMake(favourBtn.right+15, picImageView.bottom+15, 65, 24);
        moreBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-34-10, picImageView.bottom+15, 34, 24);
    }
    else
    {
        favourBtn.frame = CGRectMake(10, topicView.bottom+15, 65, 24);
        shareBtn.frame = CGRectMake(favourBtn.right+15, topicView.bottom+15, 65, 24);
        moreBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-34-10, topicView.bottom+15, 34, 24);
    }
//    favourBtn.frame = CGRectMake(10, topicView.bottom+20, 65, 24);
//    shareBtn.frame = CGRectMake(favourBtn.right+15, topicView.bottom+20, 65, 24);
//    moreBtn.frame = CGRectMake(CT_HEADER_SCREEN_WIDTH-34-10, topicView.bottom+20, 34, 24);
//    favImageView.frame = CGRectMake(10, favourBtn.bottom+28, 15, 15);
//    favCountLabel.frame = CGRectMake(30, favourBtn.bottom+28, 50, 15);
    
    
    
    if ([commentItem.liked isEqualToString:@"1"])
    {
        favBool = YES;
        [favourBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_yizan"] forState:UIControlStateNormal];
        favourLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_favoruLabel_title1" withValue:nil withTable:@"Language"];
    }
    else
    {
        favBool = NO;
        [favourBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_dianzan"] forState:UIControlStateNormal];
        favourLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_favourLabel_title" withValue:nil withTable:@"Language"];
    }

    favArray = (NSMutableArray*)commentItem.like_list;

    favNumber =(int)favArray.count;
//    if (favNumber > 9999)
//    {
//        favCountLabel.text = [NSString stringWithFormat:@"%dW",favNumber/10000];
//    }
//    if (favNumber <= 0)
//    {
//        favCountLabel.text = @"0";
//    }
//    if (favNumber>0 && favNumber <= 9999)
//    {
//        favCountLabel.text = [NSString stringWithFormat:@"%d",favNumber];
//    }
    if (favArray.count > 0)
    {
        favHeadView.frame = CGRectMake(0, favourBtn.bottom+20, CT_HEADER_SCREEN_WIDTH, 30);
        [self createFavHeadImageView:favArray];
    }
//    NSLog(@"")
    if (favHeadView.height > 0)
    {
        backGroundBottomLine.frame = CGRectMake(0, favHeadView.bottom+10, CT_HEADER_SCREEN_WIDTH, 0.5);
        backGroundBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
//        [backGroundView addSubview:backGroundBottomLine];
        backGroundView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, backGroundBottomLine.origin.y+0.5);
        commentTableView.tableHeaderView = backGroundView;
    }
    else
    {
        backGroundBottomLine.frame = CGRectMake(0, favourBtn.bottom+10, CT_HEADER_SCREEN_WIDTH, 0.5);
        backGroundBottomLine.backgroundColor = CT_HEADER_DEEPLINE_COLOR;
//        [backGroundView addSubview:backGroundBottomLine];
        backGroundView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, backGroundBottomLine.origin.y+0.5);
        commentTableView.tableHeaderView = backGroundView;
    }
    
    
    
    
}

- (void)createFavHeadImageView:(NSMutableArray *) ary
{
    [favHeadView removeAllSubviews];
    if (ary.count > 0)
    {
        favHeadView.frame = CGRectMake(0, favourBtn.bottom+20, CT_HEADER_SCREEN_WIDTH, 30);
        favHeadView.hidden = NO;
    }
    else
    {
        favHeadView.frame = CGRectMake(0, favourBtn.bottom+20, CT_HEADER_SCREEN_WIDTH, 0);
        favHeadView.hidden = YES;
    }
    
    if (favHeadView.height > 0)
    {
        backGroundBottomLine.frame = CGRectMake(0, favHeadView.bottom+10, CT_HEADER_SCREEN_WIDTH, 0.5);
        backGroundView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, backGroundBottomLine.origin.y+0.5);
        commentTableView.tableHeaderView = backGroundView;
    }
    else
    {
        backGroundBottomLine.frame = CGRectMake(0, favourBtn.bottom+10, CT_HEADER_SCREEN_WIDTH, 0.5);
        backGroundView.frame = CGRectMake(0, 0, CT_HEADER_SCREEN_WIDTH, backGroundBottomLine.origin.y+0.5);
        commentTableView.tableHeaderView = backGroundView;
    }

    
    favImageView = [[UIImageView alloc]init];
    favImageView.frame = CGRectMake(10, 8, 15, 15);
    favImageView.image = [UIImage imageNamed:@"renshu_dianzanrenshu"];
    [favHeadView addSubview:favImageView];
    
    favCountLabel = [[UILabel alloc]init];
    favCountLabel.font =[UIFont systemFontOfSize:15.0f];
    favCountLabel.textAlignment = NSTextAlignmentLeft;
    favCountLabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)ary.count];
    favCountLabel.textColor = CT_HEADER_BLACK_COLOR;
    [favHeadView addSubview:favCountLabel];
    
    if (favNumber > 9999)
    {
        favCountLabel.text = [NSString stringWithFormat:@"%d万",favNumber/10000];
        favCountLabel.frame = CGRectMake(favImageView.right+5, 8, favCountLabel.text.length*15, 15);
    }
    if (favNumber <= 0)
    {
        favCountLabel.text = @"0";
    }
    if (favNumber>0 && favNumber <= 9999)
    {
        favCountLabel.text = [NSString stringWithFormat:@"%d",favNumber];
        favCountLabel.frame = CGRectMake(favImageView.right+5, 8, favCountLabel.text.length*15, 15);
    }
    
    
    DeviceTypeAdaptation  devictType = [CTDeviceFunction deviceTypeForResolutionAdaptation];
    if (devictType == iPhone5_5s_5c ||devictType == iPhone4_4s)
    {
        long count = 0;
        if (ary.count > 6)
        {
            count = 6;
        }
        else
        {
            count = ary.count;
        }
        
        float  jianju =(CT_HEADER_SCREEN_WIDTH-110-180)/5;
        if (ary.count > 0)
        {
            for (int i = 1; i < count+1; i++)
            {
                listDetaiItme = [ary objectAtIndex:count-i];
                CommentFavourHeadBtn * favBtn = [CommentFavourHeadBtn buttonWithType:UIButtonTypeCustom];
                
                favBtn = [favBtn creatBtn:favBtn];
                favBtn.frame = CGRectMake(25+favImageView.width+favCountLabel.width+(i-1)*30+(i-1)*jianju,0,30,30);
                favBtn.delegate = self;
                favBtn.userItem = listDetaiItme;
                [favHeadView addSubview:favBtn];
            }
            
        }
    }
    else
    {
        long count = 0;
        if (ary.count > 8)
        {
            count = 8;
        }
        else
        {
            count = ary.count;
        }
        float  jianju =(CT_HEADER_SCREEN_WIDTH-110-240)/7;
        if (ary.count >0)
        {
            for (int i = 1; i < count+1; i++)
            {
                listDetaiItme = [ary objectAtIndex:count-i];
                CommentFavourHeadBtn * favBtn = [CommentFavourHeadBtn buttonWithType:UIButtonTypeCustom];
                favBtn = [favBtn creatBtn:favBtn];
                favBtn.frame = CGRectMake(25+favImageView.width+favCountLabel.width+(i-1)*30+(i-1)*jianju,0,30,30);
                
                favBtn.delegate = self;
                favBtn.userItem = listDetaiItme;
                [favHeadView addSubview:favBtn];
            }
        }
    }
    
}


//点击关注按钮
- (void)attentionBtnAction:(UIButton *) sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];
    if (attentionBtnBool == NO )
    {
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_ok_bg"] forState:UIControlStateNormal];
        attentionLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_attentioned_title" withValue:nil withTable:@"Language"];
        attentionLabel.textColor = timeLabel.textColor;
        attentionBtnBool = YES;
    }
   else if ( attentionBtnBool == YES)
    {
        timeLabel.hidden = YES;
        [attentionBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu_bg"] forState:UIControlStateNormal];
        attentionLabel.text =[CTAppLanguage localizedStringForKey:@"fllow_attention_title" withValue:nil withTable:@"Language"];
        attentionLabel.textColor = CT_HEADER_GREEN_COLOR;
        attentionBtnBool  = NO;
        
    }
    if ([self.delegate respondsToSelector:@selector(commentViewHitAttentionBtnAction:WithItem:withBool:)])
    {
        [self.delegate commentViewHitAttentionBtnAction:self WithItem:commentItem withBool:attentionBtnBool];
    }
}
//点击头像
- (void)headImageBtnAction:(UIButton *)sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    if ([self.delegate respondsToSelector:@selector(commentViewHitHeadAction:withItem:)])
    {
        [self.delegate commentViewHitHeadAction:self withItem:commentItem];
    }
}
//点击大图
- (void)picImageBtnAction:(UITapGestureRecognizer *)sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    if ([self.delegate respondsToSelector:@selector(commentViewHitPicImageBtnAction:withItem:withImageView:)])
    {
        [self.delegate commentViewHitPicImageBtnAction:self withItem:commentItem withImageView:picImageView];
    }
}
//点赞
- (void)favourBtnAction:(UIButton *)sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    CTListDetailUser *listItme = [[CTListDetailUser alloc]init];
    listItme.profile_image_url_thumb = [CTUser userInfo].profile_image_url_thumb;
    listItme.name = [CTUser userInfo].name;
    listItme.gender = [CTUser userInfo].gender;
    listItme.uid = [CTUser userInfo].uid;
    
    //需要什么返回值
    if (favBool == YES)
    {
        if(listItme.profile_image_url_thumb != nil)
        {
            for (int i = 0; i < favArray.count; i++)
            {
                CTListDetailUser *userItem = [favArray objectAtIndex:i];
                if ([userItem.uid isEqualToString:listItme.uid])
                {
                    [favArray removeObjectAtIndex:i];
                    break;
                }
                //                [favArray removeObjectAtIndex:favArray.count];
            }
            
            
            [favourBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_dianzan"] forState:UIControlStateNormal];
            favourLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_favourLabel_title" withValue:nil withTable:@"Language"];
            favNumber-=1;
            [self createFavHeadImageView:favArray];

//            if (favNumber > 9999)
//            {
//                favCountLabel.text = [NSString stringWithFormat:@"%dW",favNumber/10000];
//            }
//            if (favNumber <= 0)
//            {
//                favCountLabel.text = @"0";
//            }
//            if (favNumber>0 && favNumber <= 9999)
//            {
//                favCountLabel.text = [NSString stringWithFormat:@"%d",favNumber];
//            }
            favBool = NO;
            
        }
        
    }
    else
    {
        if(listItme.profile_image_url_thumb != nil)
        {
            
            [favArray insertObject:listItme atIndex:favArray.count];
            
            
            
            [favourBtn setBackgroundImage:[UIImage imageNamed:@"sangeanniu_yizan"] forState:UIControlStateNormal];
            favourLabel.text = [CTAppLanguage localizedStringForKey:@"fllow_favoruLabel_title1" withValue:nil withTable:@"Language"];
            favNumber+=1;
            [self createFavHeadImageView:favArray];

//            if (favNumber > 9999)
//            {
//                favCountLabel.text = [NSString stringWithFormat:@"%dW",favNumber/10000];
//            }
//            if (favNumber <= 0)
//            {
//                favCountLabel.text = @"0";
//            }
//            if (favNumber>0 && favNumber <= 9999)
//            {
//                favCountLabel.text = [NSString stringWithFormat:@"%d",favNumber];
//            }
            favBool = YES;
            
        }
        //        [favArray insertObject:[CTUser userInfo].profile_image_url_thumb atIndex:0];
    }
    

    if ([self.delegate respondsToSelector:@selector(commentViewHitFavourBtnAction:withItem:withBool:)])
    {
        [self.delegate commentViewHitFavourBtnAction:self withItem:commentItem withBool:favBool];
    }
}

//- (void)commentBtnAction:(UIButton *)sender
//{
//    if ([self.delegate respondsToSelector:@selector(commentViewHitCommentBtnaction:withItem:)])
//    {
//        [self.delegate commentViewHitCommentBtnaction:self withItem:commentItem];
//    }
//}
//分享
- (void)shareBtnAction:(UIButton *) sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    if ([self.delegate respondsToSelector:@selector(commentViewHitShareBtnAction:withItem:withImage:)])
    {
        [self.delegate commentViewHitShareBtnAction:self withItem:commentItem withImage:picImageView.image];
    }
}
//更多
- (void)moreBtnAction:(UIButton *) sender
{
    isKeyBoardShow = YES;
    [commentTextView resignFirstResponder];

    if ([self.delegate respondsToSelector:@selector(commentViewHitMoreBtnAction:withItem:)])
    {
        [self.delegate commentViewHitMoreBtnAction:self withItem:commentItem];
    }
}
#pragma mark - favour head btn -

-(void)favourHeadBtnClickedAction:(CommentFavourHeadBtn *)btn withUserItem:(CTListDetailUser *)itm
{
    //    [CTDebugManager showDebugLogInfo:[NSString stringWithFormat:@"%@",itm]];
    if ([self.delegate respondsToSelector:@selector(commentViewHitFavBtnHeadAction:withItem:)])
    {
        [self.delegate commentViewHitFavBtnHeadAction:self withItem:itm];
    }
    
}

-(void)selectTopicAction:(CTTopicView *)view withItem:(CTTopic *)topicitem
{
    if ([self.delegate respondsToSelector:@selector(commentViewHitTopicAction:withItem:)])
    {
         [self.delegate commentViewHitTopicAction:self withItem:topicitem];
    }
}


@end











#import "CTDiscoveryItems.h"
@interface CommentFavourHeadBtn()
{
    CTListDetailUser * item;
}

@end


@implementation CommentFavourHeadBtn
@synthesize delegate;

- (void)dealloc
{
    delegate = nil;
}

-(CommentFavourHeadBtn *)creatBtn:(CommentFavourHeadBtn *)btn
{
    [btn addTarget:self action:@selector(btnCliked:) forControlEvents:UIControlEventTouchUpInside];
    btn.frame = CGRectMake(0,0,30,30);
    btn.layer.masksToBounds = YES;
    btn.layer.cornerRadius  = 15;
    [btn setBackgroundImage:[UIImage imageNamed:@"head"] forState:UIControlStateNormal];
    
    return btn;
}

-(void)btnCliked:(id)sender
{
    if ([self.delegate respondsToSelector:@selector(favourHeadBtnClickedAction: withUserItem:)]) {
        [self.delegate favourHeadBtnClickedAction:self withUserItem:item];
    }
}

#pragma mark - setter -

-(void)setListDetailUserItem:(CTListDetailUser *)userItem
{
    item = userItem;
    
   
    [CTRequestUtil requestImgWithUrl:userItem.profile_image_url_thumb withCompletionSuccessHandler:^(UIImage *img) {
        [self setBackgroundImage:img forState:UIControlStateNormal];
    } withFailedHandler:^(NSError *error) {
        
    }];
}





@end



